from pydantic import BaseModel, Field
from datetime import datetime

# 嵌套的 weather 对象模型
# 使用 Field(alias=...) 来自动映射数据库列名到模型字段名
class WeatherInfo(BaseModel):
    wind_direction: str | None = Field(None, alias="winddirect")
    wind_speed: str | None = Field(None, alias="windspeed")
    temp_min: int | None = Field(None, alias="mintemp")
    temp_max: int | None = Field(None, alias="maxtemp")
    humidity: int | None
    rain: int | None
    air_quality_index: int | None = Field(None, alias="air")
    air_quality_level: int | None = Field(None, alias="airlevel")

    class Config:
        from_attributes = True # 允许从 ORM 模型（或类似对象）创建

# data 字段的模型
class WeatherData(BaseModel):
    requested_time: datetime
    record_time: datetime
    weather: WeatherInfo

# 完整的 API 响应模型
class WeatherResponse(BaseModel):
    code: int
    message: str
    data: WeatherData | None = None